@rem 说明：Windows平台命令行编译脚本
@rem 作用：通过批处理脚本命令行编译VS工程
@echo off
@rem usage: build.bat Release/Debug Win32/x64

@rem set build_config="Debug|Win32"
@rem set build_config="Release|Win32"
@rem set build_config=$ALL

@rem 当前环境设置只在本文件中有效
@setlocal
::项目名称
set temProjectName=OfficeReadWrite_QT

::以下的目录的相对路径都是相对于脚本文件而言

::项目路径
set temProjectDirPath=..\OfficeReadWrite_QT\

::脚本文件目录
set temCreateMake=.\

::bin目录路径
set temBinDirPath=%temProjectDirPath%bin\

::依赖库路径 depends
set temDependsDir=%temProjectDirPath%depends\

set build=Release
set platform=x64

@rem 各种文件和路径
set VCVARS="C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build/vcvarsall.bat"
set DEVENV="C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE/devenv.exe"

::Qt版本号路径
set Qt5_13_2=C:\Qt\Qt5.13.2\
set Qt5_12_3=D:\Qt\Qt5.12.3\
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::以下的代码无须改动，只需改动上边的定义即可:::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if EXIST %Qt5_13_2% (
	set VersionNumber=5.13.2
	set QtPath=%Qt5_13_2%
) else if EXIST %Qt5_12_3% (
	set VersionNumber=5.12.3
	set QtPath=%Qt5_12_3%
) 

set build_config="%build%|%platform%"

@echo %date% %time% >build.log

@rem 当前脚本所在路径
@echo "编译目录..."
@echo %~dp0
set build_root = %~dp0

@rem 设置解决方案路径
set SOlUTION="%~dp0%temProjectDirPath%%temProjectName%.sln"
@echo "解决方案..."
@echo %SOLUTION%

@rem 检查文件路径配置
if not exist %VCVARS% echo "VCVARS不存在！" &goto end
if not exist %DEVENV% echo "DEVENV不存在！" &goto end
if not exist %SOlUTION% echo "SOlUTION不存在！" &goto end

@rem 删除输出文件
if exist build.log del build.log

@rem 编译环境配置
@echo "环境配置..."
if %platform%=="Win32" (
echo "Windows 32位环境配置..."
call %VCVARS% x86)

if %platform%=="x64" (
echo "Windows 64位环境配置..."
call %VCVARS% x86_amd64)

@echo build_config:%build_config%,please waiting

::为Qt使用设置环境…
echo Setting up environment for Qt usage...
set PATH=%QtPath%\%VersionNumber%\msvc2017_64\bin;%QtPath%/Tools/msvc2017_64\bin;%PATH%
set PATH=%VS2019PATH%;%PATH%

@echo "开始编译"
%DEVENV% %SOlUTION% /rebuild %build_config% /out build.log

@rem 打印编译信息
@rem notepad build.log
type build.log

::拷贝exe文件到bin目录下
@echo "拷贝exe文件到bin目录下..."
xcopy %temProjectDirPath%x64\Release\*.exe %temBinDirPath% /E

::添加Qt依赖项
@echo "添加Qt依赖项..."
for /r %temBinDirPath% %%i in (*.exe) do windeployqt %%i

::拷贝依赖库dll到bin目录下
@echo "拷贝依赖库dll到bin目录下..."
start /wait "call get_releaseFiles.bat" cmd /c call %build_root%%temDependsDir%get_releaseFiles.bat
xcopy %temDependsDir%release\*.* %temBinDirPath% /s /e /c /y /h /r

::拷贝translations文件
for /r %temProjectDirPath% %%i in (*.qm) do copy %%i %temBinDirPath%translations\

::"C:\Program Files (x86)\Inno Setup 5\ISCC.exe" %temCreateMake%\makeAll.iss

:end
@rem pause
@endlocal

pause